/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package pkg0912144.pkg0912207.array;

import Algorithm.Algorithm;
import StrategyCompare.Ascending;
import StrategyCompare.Descending;
import java.lang.reflect.Array;

/**
 *
 * @author khangdc
 */
public class HKBox<E> {

    private E[] a;

    @SuppressWarnings({"unchecked"})
    public HKBox(Class<E> c, int s) {
        a = (E[]) Array.newInstance(c, s);
    }

    public E get(int i) {
        return a[i];
    }

    public void set(int i, E e) {
        a[i] = e;
    }

    public int getSize() {
        int size = 0;
        for(int i = 0; i < a.length; i++)
        {
            if( a[i] != null)
                size++;
        }
        return size;
    }

    public void sortDes(Algorithm<E> sortAlgo, comparetor.Comparetor<E> compare) {
        sortAlgo.sort(this, new Descending(),compare);
    }
    public void sortAsc(Algorithm<E> sortAlgo,comparetor.Comparetor<E> compare) {
        sortAlgo.sort(this, new Ascending(),compare);
    }
}
